package com.captain.special.字符串;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/5 16:56
 */
public class 替换空格剑指Offer05 {
    public static void main(String[] args) {
        new 替换空格剑指Offer05().replaceSpace("We are happy.");
    }

    public String replaceSpace(String s) {
        char[] chars = s.toCharArray();
        char[] res = new char[s.length() * 3];
        int index = 0;
        for (char aChar : chars) {
            if (aChar == ' ') {
                res[index++] = '%';
                res[index++] = '2';
                res[index++] = '0';
            } else {
                res[index++] = aChar;
            }
        }
        return new String(res, 0, index);
    }
}
